package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.entity.SurgeryItem;
import com.woniu.entity.Ward;
import com.woniu.mapper.WardMapper;
import com.woniu.service.WardService;
import com.woniu.utils.ResponseEnum;
import com.woniu.utils.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WardServiceImpl implements WardService {
    @Resource
    private WardMapper wardMapper;
    @Override
    public ResponseUtil findAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Ward> wardList = wardMapper.findAll();
        PageInfo pageInfo = new PageInfo(wardList);
        return wardList != null ?ResponseUtil.get(ResponseEnum.OK,pageInfo)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil updateWard(Integer id) {
        int rows = wardMapper.updateWard(id);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil insertSelective(Ward record) {
        int rows = wardMapper.insertSelective(record);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK, record)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil updateByPrimaryKeySelective(Ward record) {
        int rows = wardMapper.updateByPrimaryKeySelective(record);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }


    @Override
    public ResponseUtil selectByCondition(String roomName,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Ward> wardList = wardMapper.selectByCondition(roomName);
        PageInfo pageInfo = new PageInfo(wardList);
        return wardList!=null ? ResponseUtil.get(ResponseEnum.OK,pageInfo)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
}
